<?php
namespace app\log\model;
use app\common\model\Common;
use think\Db;
class Log extends Common
{
	protected $table = "mps_operation_log";
	protected $autoWriteTimestamp = true;
	protected $createTime = 'addtime';
    protected $updateTime = false;
    protected $append = ['type_text','admin','id'];


    /**
	 * 获取列表
	 * @param array $where 查询条件
	 * @param string $order 排序条件
	 * @param intger $page 当前页数
	 * @param intger $row 每页条数
	 * @param string $search 关键字检索条件
	 */
	public function listData($where, $order, $page, $row, $search = '')
	{
		if($where === false) return [];
		if($row == 'limit'){
			$list = $this->where($search)->where($where)->order($order)->select();
		}else{
			$list = $this->where($search)->where($where)->order($order)->page($page, $row)->select();
		}
		foreach($list as $k => $v){
			$v->id = $k+1;
		}
		return $list;
	}

	/**
	 * 获取操作类型
	 */
	public function getType()
	{
		return [0=>"删除",1=>"添加",2=>"登录",3=>"退出"];
	}
	/**
	 * 获取操作者列表
	 */
	public function getAdmin()
	{
		return Db::name('Admin')->field('account,nkname,admin_id')->select();
	}

	/**
	 * 获取器
	 */
    public function getAddtimeAttr($value)
    {
    	return $value > 0 ? date('Y-m-d H:i:s',$value) : '----';
    }
    public function getTypeTextAttr($value,$data)
    {
    	$type = self::getType();
    	return isset($type[$data['type']]) ? $type[$data['type']] : '异常';
    }
    public function getAdminAttr($value,$data)
    {
    	return Db::name('Admin')->field('account,nkname')->where('admin_id',$data['admin_id'])->find();
    }
}